import React, { useState } from 'react';
import { Button, Field, Toast } from 'react-vant';
// import { useNavigate } from 'react-router-dom';
// import './Index.css';
import { postHttp } from '../../request/api';

interface CommentProps {
  sickCircleId: number;
  onCommentSuccess?: () => void;
  onCommentSucce?: () => void;
}

const Comment: React.FC<CommentProps> = ({ sickCircleId, onCommentSuccess, onCommentSucce }) => {
  const [content, setContent] = useState('');
  const [loading, setLoading] = useState(false);
  // const navigate = useNavigate();

  const handleSubmit = async () => {
    if (!content.trim()) {
      Toast.info('请输入评论内容');
      return;
    }

    setLoading(true);
    try {
      // const params = {
      //   sickCircleId,
      //   content: content,
      // };log
      console.log(onCommentSucce);

      const response = await postHttp('/health/user/sickCircle/verify/v1/publishComment', { sickCircleId, content });
      console.log(sickCircleId, content, response);

      if (response.data.status === '0000') {
        Toast.success('评论成功');
        setContent('');
        onCommentSuccess?.();
        onCommentSucce?.();

      } else {
        Toast.fail(response.data.message || '评论失败');
      }
    } catch (error: any) {
      Toast.fail(error.response?.data?.message || '网络错误，请稍后重试');
      console.error('评论发布失败:', error);
    } finally {
      setLoading(false);
    }
  };

  return (
    <div className="comment-box">
      <div className="comment-input">
        <Field
          value={content}
          onChange={setContent}
          placeholder="写下你的建议..."
          rows={3}
          type="textarea"
          maxLength={200}
          showWordLimit
        />
      </div>
      <div className="comment-button">
        <Button
          type="primary"
          size="small"
          loading={loading}
          disabled={loading || !content.trim()}
          onClick={handleSubmit}
        >
          发表建议
        </Button>
      </div>
    </div>
  );
};

export default Comment; 